/**
 * Copyright 2009 University of  Washington
 * This code is released under the GPL version 3 - with a copy of the license included
 * @author Maya Hao Li
 *
 */
package seedpod.webapp.view.htmlwidget;

import java.util.Hashtable;
import java.util.Vector;

public class Menu extends GenericHtmlWidget
{
  public static final String CSS_CLASS = "classMenuItem";
  private Hashtable<String, Object> menuItems;
  private Vector<String> menuItemNames;

  public Menu(String widgetID)
  {
    this._widgetID = widgetID;
    menuItems = new Hashtable<String, Object>();
    menuItemNames = new Vector<String>();
    this.setCssClass(CSS_CLASS);
  }

  public void addMenuItem(GenericHtmlWidget w)
  {
    menuItemNames.add(w._widgetID);
    menuItems.put(w._widgetID, w);
  }

  public String render()
  {
    GenericHtmlWidget menuItem;

    String menu = "<table cellspacing=\"5\" cellpadding=\"0\" border=\"0\">";
    for (int i = 0; i < menuItemNames.size(); i++)
    {
      menu += "<tr><td class=\""+_cssClass+"\" nowrap>";
      menuItem = (GenericHtmlWidget)menuItems.get((String)menuItemNames.get(i));
      menu += menuItem.render();
      menu += "</td></tr>";
    }
    menu += "</table>";
    return menu;
  }
}